{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 669,
   "id": "8920a437-a70f-409b-86f3-c9f656681129",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import *\n",
    "from pyecharts.components import Table\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.commons.utils import JsCode\n",
    "import random\n",
    "import datetime\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from pyecharts.charts import Geo\n",
    "from pyecharts.globals import ChartType,SymbolType\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 279,
   "id": "37b0c554-6693-4afb-921d-73c122bb05e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_2015 = pd.read_csv('./中国大学数据/bcur_2015.csv')\n",
    "data_2016 = pd.read_csv('./中国大学数据/bcur_2016.csv')\n",
    "data_2017 = pd.read_csv('./中国大学数据/bcur_2017.csv')\n",
    "data_2018 = pd.read_csv('./中国大学数据/bcur_2018.csv')\n",
    "data_2019 = pd.read_csv('./中国大学数据/bcur_2019.csv')\n",
    "data_2020 = pd.read_csv('./中国大学数据/bcur_2020.csv',encoding='gbk')\n",
    "data_2021 = pd.read_csv('./中国大学数据/bcur_2021.csv')\n",
    "data_2022 = pd.read_csv('./中国大学数据/bcur_2022.csv')\n",
    "data_2023 = pd.read_excel('./中国大学数据/中国大学综合排名2023.xlsx')\n",
    "data_2023.to_csv('bcur_2023.csv', index=False)\n",
    "data_2024 = pd.read_csv('./中国大学数据/中国大学综合排名2024.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 288,
   "id": "648b14e5-92ca-4806-ab0e-d565cb998346",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 把2015-2022的列名换一下\n",
    "data_frames = [data_2015,data_2016,data_2017,data_2018,data_2019,data_2020,data_2021,data_2022,data_2023,data_2024]\n",
    "column_mapping = {\n",
    "    \"univNameCn\": \"院校名称\",\n",
    "    \"学校名称\":'院校名称',\n",
    "    \"中文名\":\"院校名称\",\n",
    "    \"univNameEn\": \"英文名\",\n",
    "    \"univTags\": \"层次\",\n",
    "    \"univCategory\": \"类型\",\n",
    "    \"province\": \"地区\",\n",
    "    \"score\": \"评分\",\n",
    "    \"ranking\": \"排名\"\n",
    "}\n",
    "for data_frame in data_frames:\n",
    "    data_frame.rename(columns=column_mapping, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 289,
   "id": "b7d8871d-758b-4ef7-8cca-54e76716faec",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 在每个文件中添加年份\n",
    "years = [\"2015\", \"2016\", \"2017\", \"2018\", \"2019\", \"2020\", \"2021\", \"2022\", \"2023\"]\n",
    "for i, data_frame in enumerate(data_frames[:9]):\n",
    "    data_frame[\"年份\"] = years[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 290,
   "id": "23dca1b0-76bd-45b2-b5a7-9a725ba934b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "combined_df = pd.concat(data_frames, ignore_index=True)\n",
    "result_df = combined_df.groupby(['院校名称', '年份'])['排名'].apply(lambda x: x.values[0] if len(x) > 0 else None).unstack(fill_value=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 291,
   "id": "dc37cd20-273c-4d41-a865-31048a26d399",
   "metadata": {},
   "outputs": [],
   "source": [
    "fi_school = pd.merge(data_2024, result_df, left_on='院校名称',right_index=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 535,
   "id": "e48f9057-babd-4827-b483-3d949b2aaee6",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_frame = pd.read_excel('./中国大学数据/全国高校名单及详细指标.xls')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 536,
   "id": "465b6e22-280d-43dc-9eb5-065c1c09df8b",
   "metadata": {},
   "outputs": [],
   "source": [
    "all_school = pd.merge(fi_school,data_frame, left_on='院校名称',right_on='院校名称')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ed55bc5-81e4-4795-8401-20260cce1d22",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "f8db2641-ee48-4aad-9f37-03381153a25b",
   "metadata": {},
   "source": [
    "## 任务2. 数据分析任务-数据统计分析任务(工具: Matplotlib/Seaborn/Pyecharts都可以)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "81a7375d-ba91-4938-832d-769a3840529d",
   "metadata": {},
   "source": [
    "### 需求4. 计算各个省份高校的数量,找出TOP10教育大省,计算各个地级市的大学数量,找出TOP10教育城市.可以合理利用可视化方式进行. 柱状图/饼图/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 345,
   "id": "b984221a-8138-4095-b753-2e02a1ed0c4e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.globals import ThemeType"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 542,
   "id": "49679c95-1cfc-4f4b-b3d1-a32ce8131221",
   "metadata": {},
   "outputs": [],
   "source": [
    "top_pra = data_frame.groupby('省份').agg(\n",
    "    {\n",
    "       '院校名称':'count'\n",
    "    }\n",
    ").sort_values(by='院校名称').iloc[-10::].astype('int').reset_index().values.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 543,
   "id": "75a849ad-6dfc-4408-a1ab-2b57d99d1755",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['浙江', 122],\n",
       " ['湖北', 142],\n",
       " ['湖南', 145],\n",
       " ['河北', 149],\n",
       " ['四川', 153],\n",
       " ['安徽', 154],\n",
       " ['河南', 169],\n",
       " ['山东', 176],\n",
       " ['江苏', 196],\n",
       " ['广东', 221]]"
      ]
     },
     "execution_count": 543,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "top_pra"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 544,
   "id": "d2896a2d-1d55-4a8e-a183-8eee2cddd2a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "itemstyle2 = {\n",
    "    'normal':{\n",
    "        'color':JsCode(\"\"\"new echarts.graphic.LinearGradient(0, 0, 0, 1, [\n",
    "          { offset: 0, color: '#FF8008' },\n",
    "          { offset: 1, color: '#FFC837' }\n",
    "        ],false)\"\"\"),\n",
    "        'barBorderRadius':[2,2,2,2],\n",
    "        'shadowColor':'#F9D423',\n",
    "        'shadowBlur':10,\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 545,
   "id": "507ad568-9bdb-44b2-a131-0a4265db4e44",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\asus\\\\pyecharts模块\\\\result\\\\需求4：TOP10教育大省.html'"
      ]
     },
     "execution_count": 545,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bar = (Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT,bg_color='#f5f5f5',page_title='TOP10教育大省'))\n",
    "       .add_xaxis([i[0] for i in top_pra])\n",
    "       .add_yaxis(\n",
    "           series_name='TOP10教育大省',\n",
    "           y_axis=[i[1] for i in top_pra],\n",
    "           itemstyle_opts=itemstyle2,\n",
    "           bar_width='35%',\n",
    "           \n",
    "           \n",
    "       )\n",
    "       .set_global_opts(\n",
    "           datazoom_opts=[opts.DataZoomOpts(type_='inside'),opts.DataZoomOpts()],  # 加伸缩条和滚轮缩放\n",
    "           title_opts=opts.TitleOpts(title='TOP10教育大省',pos_left='center'),\n",
    "           legend_opts=opts.LegendOpts(is_show=True,\n",
    "                                       textstyle_opts=opts.TextStyleOpts(color='auto'),\n",
    "                                       legend_icon='diamond',\n",
    "                                       pos_top='5%'\n",
    "                                      ),\n",
    "           tooltip_opts=opts.TooltipOpts(trigger='axis',axis_pointer_type='shadow'),  # 添加提示框\n",
    "           xaxis_opts=opts.AxisOpts(splitline_opts={'show':False}),\n",
    "           yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True))\n",
    "       )\n",
    "       .set_series_opts(label_opts=opts.LabelOpts(is_show=True,position='top'))\n",
    "      )\n",
    "bar.render('./result/需求4：TOP10教育大省.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 546,
   "id": "867405bd-28b9-4d25-bdf3-37a7a116dc37",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 饼图pie\n",
    "color=['#5433FF','#20BDFF','#c471ed','#F7971E','#c2e59c','#b6fbff','#f2709c','#faaca8','#50C9C3','#4776E6']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 547,
   "id": "49ad0a72-2f4c-4d1d-b7a6-1ac62aee648e",
   "metadata": {},
   "outputs": [],
   "source": [
    "pieitemstyle = {\n",
    "    'normal':{\n",
    "        'shadowColor':'#dee7f3',\n",
    "        'shadowBlur':10,\n",
    "        'borderRadius':10,\n",
    "        'borderColor':'auto'\n",
    "    }\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 548,
   "id": "18156072-a53f-42b7-9edb-b8ec9c4f03ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\asus\\\\pyecharts模块\\\\result\\\\需求4：TOP教育大省（饼图）.html'"
      ]
     },
     "execution_count": 548,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 富文本\n",
    "rich_text = {\n",
    "    \"a\": {\"color\": \"#999\", \"lineHeight\": 22, \"align\": \"center\"},\n",
    "    \"abg\": {\n",
    "        \"backgroundColor\": \"#e2edf8\",\n",
    "        \"width\": \"100%\",\n",
    "        \"align\": \"right\",\n",
    "        \"height\": 22,\n",
    "        \"borderRadius\": [4, 4, 4, 4],\n",
    "    },\n",
    "    \"hr\": {\n",
    "        \"borderColor\": \"#d5e3f9\",\n",
    "        \"width\": \"100%\",\n",
    "        \"borderWidth\": 0.5,\n",
    "        \"height\": 0,\n",
    "    },\n",
    "    \"b\": {\"fontSize\": 16, \"lineHeight\": 33},\n",
    "    \"per\": {\n",
    "        \"color\": \"#eee\",\n",
    "        \"backgroundColor\": \"auto\",\n",
    "        \"padding\": [2, 4],\n",
    "        \"borderRadius\": 2,\n",
    "    },\n",
    "}\n",
    "pie  = (\n",
    "    Pie(init_opts=opts.InitOpts(page_title='TOP10教育大省饼图'))\n",
    "    .add('TOP10教育大省',top_pra[::-1],itemstyle_opts=pieitemstyle,\n",
    "         radius=['20%','60%'],\n",
    "         rosetype='radius',\n",
    "         label_opts=opts.LabelOpts(position='outside',\n",
    "                                   formatter=\"{a|{a}}{abg|}\\n{hr|}\\n {b|{b}: }{c}  {per|{d}%}  \",\n",
    "                                   rich=rich_text),\n",
    "         is_legend_hover_link=True,\n",
    "         selected_mode='series',\n",
    "         \n",
    ")\n",
    "    .set_colors(['#5433FF','#20BDFF','#c471ed','#F7971E','#4776E6','#b6fbff','#f2709c','#faaca8','#50C9C3','#c2e59c'])\n",
    ")\n",
    "pie.options['series'][0]['padAngle']=4\n",
    "pie.render('./result/需求4：TOP教育大省（饼图）.html')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6a0d8df-c22c-4085-bf9f-675c552c680f",
   "metadata": {},
   "source": [
    "### 需求5. 计算各个省份民办/公办高校的数量,并对TOP10高校完成可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 691,
   "id": "c4ea9f10-fa87-4e4e-a51b-0f78315a82de",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data_frame.groupby(['省份','办学性质']).agg(\n",
    "    {\n",
    "        '院校名称':'count'\n",
    "    }\n",
    ").reset_index().sort_values(by='院校名称')[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 607,
   "id": "747eaaab-5d26-4bdd-928d-e9ad951911d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_g = data[data['办学性质']=='公办'].reset_index()[['省份','院校名称']][:10].values.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 611,
   "id": "802f6559-c8c7-4ee1-8bb8-61cb6ed87b23",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_m = data[data['办学性质']=='民办'].reset_index()[['省份','院校名称']][:10].values.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 618,
   "id": "dcfe1078-2b12-4f0b-9025-008ebb7a5922",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\asus\\\\pyecharts模块\\\\result\\\\公办学校数量省份TOP10.html'"
      ]
     },
     "execution_count": 618,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pie  = (\n",
    "    Pie(init_opts=opts.InitOpts(page_title='公办学校数量省份TOP10(饼图)'))\n",
    "    .add('公办学校数量省份TOP10',data_g,itemstyle_opts=pieitemstyle,\n",
    "         radius=['20%','60%'],\n",
    "         rosetype='radius',\n",
    "         label_opts=opts.LabelOpts(position='outside',\n",
    "                                   formatter=\"{a|{a}}{abg|}\\n{hr|}\\n {b|{b}: }{c}  {per|{d}%}  \",\n",
    "                                   rich=rich_text),\n",
    "         is_legend_hover_link=True,\n",
    "         selected_mode='series',\n",
    "         \n",
    ")\n",
    "    .set_colors(['#5433FF','#20BDFF','#c471ed','#F7971E','#4776E6','#b6fbff','#f2709c','#faaca8','#50C9C3','#c2e59c'])\n",
    ")\n",
    "pie.options['series'][0]['padAngle']=4\n",
    "pie.render('./result/公办学校数量省份TOP10.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 613,
   "id": "6945c256-b986-4983-9dfa-e843e455b9da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\asus\\\\pyecharts模块\\\\result\\\\需求5：民办学校数量省份TOP10.html'"
      ]
     },
     "execution_count": 613,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pie  = (\n",
    "    Pie(init_opts=opts.InitOpts(page_title='民办学校数量省份TOP10(饼图)'))\n",
    "    .add('民办学校数量省份TOP10',data_m,itemstyle_opts=pieitemstyle,\n",
    "         radius=['20%','60%'],\n",
    "         rosetype='radius',\n",
    "         label_opts=opts.LabelOpts(position='outside',\n",
    "                                   formatter=\"{a|{a}}{abg|}\\n{hr|}\\n {b|{b}: }{c}  {per|{d}%}  \",\n",
    "                                   rich=rich_text),\n",
    "         is_legend_hover_link=True,\n",
    "         selected_mode='series',\n",
    "         \n",
    ")\n",
    "    .set_colors(['#5433FF','#20BDFF','#c471ed','#F7971E','#4776E6','#b6fbff','#f2709c','#faaca8','#50C9C3','#c2e59c'])\n",
    ")\n",
    "pie.options['series'][0]['padAngle']=4\n",
    "pie.render('./result/需求5：民办学校数量省份TOP10.html')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "777ad817-47e4-4dcf-a8e0-217a8d461369",
   "metadata": {},
   "source": [
    "### 需求6. 将所给数据按区域划分为7大区,如华南,华北...等.统计各个大区高校的院校数量,院校类型的数量分布情况,办学类型分布情况,以及办学性质分布情况.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 620,
   "id": "c975a4c7-8d6b-434b-8ea4-c4c39f68f5e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "china_regions={  \n",
    "    \"北京\": \"华北地区\",  \n",
    "    \"天津\": \"华北地区\",  \n",
    "    \"河北\": \"华北地区\",  \n",
    "    \"山西\": \"华北地区\",  \n",
    "    \"内蒙古\": \"华北地区\",  \n",
    "    \"辽宁\": \"东北地区\",  \n",
    "    \"吉林\": \"东北地区\",  \n",
    "    \"黑龙江\": \"东北地区\",  \n",
    "    \"上海\": \"华东地区\",  \n",
    "    \"江苏\": \"华东地区\",  \n",
    "    \"浙江\": \"华东地区\",  \n",
    "    \"安徽\": \"华东地区\",  \n",
    "    \"福建\": \"华东地区\",  \n",
    "    \"江西\": \"华东地区\",  \n",
    "    \"山东\": \"华东地区\",  \n",
    "    \"河南\": \"华中地区\",  \n",
    "    \"湖北\": \"华中地区\",  \n",
    "    \"湖南\": \"华中地区\",  \n",
    "    \"广东\": \"华南地区\",  \n",
    "    \"广西\": \"华南地区\",  \n",
    "    \"海南\": \"华南地区\",  \n",
    "    \"重庆\": \"西南地区\",  \n",
    "    \"四川\": \"西南地区\",  \n",
    "    \"贵州\": \"西南地区\",  \n",
    "    \"云南\": \"西南地区\",  \n",
    "    \"西藏\": \"西南地区\",  \n",
    "    \"陕西\": \"西北地区\",  \n",
    "    \"甘肃\": \"西北地区\",  \n",
    "    \"青海\": \"西北地区\",  \n",
    "    \"宁夏\": \"西北地区\",  \n",
    "    \"新疆\": \"西北地区\",  \n",
    "    \"香港\": \"华南地区\",  \n",
    "    \"澳门\": \"华南地区\",  \n",
    "    \"台湾\": \"华东地区\"  \n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 642,
   "id": "310e328c-01e8-472d-981a-8cdcd91f2fac",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_frame['大区'] = data_frame['省份'].map(china_regions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 655,
   "id": "1ebd0c4a-41db-4105-94fd-31c86fafa0a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_daqu = data_frame.groupby(['大区','院校类型','办学类型','办学性质']).agg(\n",
    "    {\n",
    "        '院校名称' : 'count'\n",
    "    }\n",
    ").reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 692,
   "id": "3a11d195-7bab-4334-8a41-7d2849051238",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>大区</th>\n",
       "      <th>院校类型</th>\n",
       "      <th>办学类型</th>\n",
       "      <th>办学性质</th>\n",
       "      <th>院校名称</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东北地区</td>\n",
       "      <td>体育类</td>\n",
       "      <td>专科（高职）</td>\n",
       "      <td>公办</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>东北地区</td>\n",
       "      <td>体育类</td>\n",
       "      <td>普通本科</td>\n",
       "      <td>公办</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>东北地区</td>\n",
       "      <td>其他</td>\n",
       "      <td>专科（高职）</td>\n",
       "      <td>公办</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>东北地区</td>\n",
       "      <td>农林类</td>\n",
       "      <td>专科（高职）</td>\n",
       "      <td>公办</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>东北地区</td>\n",
       "      <td>农林类</td>\n",
       "      <td>普通本科</td>\n",
       "      <td>公办</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>260</th>\n",
       "      <td>西南地区</td>\n",
       "      <td>财经类</td>\n",
       "      <td>专科（高职）</td>\n",
       "      <td>公办</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>261</th>\n",
       "      <td>西南地区</td>\n",
       "      <td>财经类</td>\n",
       "      <td>专科（高职）</td>\n",
       "      <td>民办</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>262</th>\n",
       "      <td>西南地区</td>\n",
       "      <td>财经类</td>\n",
       "      <td>普通本科</td>\n",
       "      <td>中外合作办学</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>263</th>\n",
       "      <td>西南地区</td>\n",
       "      <td>财经类</td>\n",
       "      <td>普通本科</td>\n",
       "      <td>公办</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>264</th>\n",
       "      <td>西南地区</td>\n",
       "      <td>财经类</td>\n",
       "      <td>普通本科</td>\n",
       "      <td>民办</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>265 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       大区 院校类型    办学类型    办学性质  院校名称\n",
       "0    东北地区  体育类  专科（高职）      公办     2\n",
       "1    东北地区  体育类    普通本科      公办     3\n",
       "2    东北地区   其他  专科（高职）      公办     1\n",
       "3    东北地区  农林类  专科（高职）      公办     8\n",
       "4    东北地区  农林类    普通本科      公办     9\n",
       "..    ...  ...     ...     ...   ...\n",
       "260  西南地区  财经类  专科（高职）      公办     9\n",
       "261  西南地区  财经类  专科（高职）      民办     6\n",
       "262  西南地区  财经类    普通本科  中外合作办学     2\n",
       "263  西南地区  财经类    普通本科      公办     7\n",
       "264  西南地区  财经类    普通本科      民办     8\n",
       "\n",
       "[265 rows x 5 columns]"
      ]
     },
     "execution_count": 692,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_daqu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 659,
   "id": "dbec3059-9235-46db-a828-4540461b29c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "list_daqu = data_daqu.groupby('大区').agg({'院校名称':'count'}).reset_index().values.tolist()  # 大区的院校数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc41b888-8ec7-4c1b-9bc8-09db36a96c91",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 668,
   "id": "3f90932e-d17d-4179-b8f8-b921aafd6266",
   "metadata": {},
   "outputs": [],
   "source": [
    "list_type = data_daqu.groupby('院校类型').agg({'院校名称':'count'}).sort_values(by='院校名称')[::-1].reset_index().values.tolist()  # 院校类型分布"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 667,
   "id": "93627fd1-e70f-4c02-a42a-2d79c6bc18e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "list_1 = data_daqu.groupby('办学类型').agg({'院校名称':'count'}).sort_values(by='院校名称')[::-1].reset_index().values.tolist()  # 办学类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 666,
   "id": "7cffce2e-ce13-405a-a939-9706e9875ad3",
   "metadata": {},
   "outputs": [],
   "source": [
    "list2 = data_daqu.groupby('办学性质').agg({'院校名称':'count'}).sort_values(by='院校名称')[::-1].reset_index().values.tolist()  # 办学性质"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72dd5678-4fc0-4dbd-bd43-b7d8d172f4f9",
   "metadata": {},
   "source": [
    "# 地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c203ec8-0d03-4933-b9f9-e1fdb9306e0b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ccfa7f31-c822-4612-bf65-9c5fd1d77d6c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 678,
   "id": "7605d2c4-cf4a-48a8-bffb-da26f92e89d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "itemstyle_map = {\n",
    "    'normal':{\n",
    "        'shadowColor':'#dee7f3',\n",
    "        'shadowBlur':10,\n",
    "        'borderWidth':3,\n",
    "        'borderRadius':10,\n",
    "        'borderColor':JsCode(\"\"\"new echarts.graphic.LinearGradient(0, 0, 1, 1, [\n",
    "          { offset: 0, color: '#f12711' },\n",
    "          { offset: 1, color: '#f5af19' }\n",
    "        ],false)\"\"\"), \n",
    "    }\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 693,
   "id": "5bd8171f-d8a0-4902-bdfb-c5606962ef66",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "0",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[693], line 3\u001b[0m\n\u001b[0;32m      1\u001b[0m maps \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m      2\u001b[0m     \u001b[43mMap\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m----> 3\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd\u001b[49m\u001b[43m(\u001b[49m\u001b[43mseries_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m高校数量\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43mdata_pair\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mchina_regions\u001b[49m\u001b[43m,\u001b[49m\u001b[43mmaptype\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mchina\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m      4\u001b[0m \u001b[43m         \u001b[49m\u001b[43mis_map_symbol_show\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m  \u001b[49m\u001b[38;5;66;43;03m# 关闭点\u001b[39;49;00m\n\u001b[0;32m      5\u001b[0m \u001b[43m         \u001b[49m\u001b[43mis_roam\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m  \u001b[49m\u001b[38;5;66;43;03m# 取消滚轮缩放功能\u001b[39;49;00m\n\u001b[0;32m      6\u001b[0m \u001b[43m         \u001b[49m\u001b[43mcenter\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m110\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m35\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m  \u001b[49m\u001b[38;5;66;43;03m# 位置\u001b[39;49;00m\n\u001b[0;32m      7\u001b[0m \u001b[43m         \u001b[49m\u001b[43mzoom\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1.5\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m  \u001b[49m\u001b[38;5;66;43;03m# 控制地图大小\u001b[39;49;00m\n\u001b[0;32m      8\u001b[0m \u001b[43m         \u001b[49m\u001b[38;5;66;43;03m# itemstyle_opts=itemstyle_map,\u001b[39;49;00m\n\u001b[0;32m      9\u001b[0m \u001b[43m         \u001b[49m\n\u001b[0;32m     10\u001b[0m \u001b[43m        \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     11\u001b[0m     \n\u001b[0;32m     12\u001b[0m     \u001b[38;5;241m.\u001b[39mset_global_opts(visualmap_opts\u001b[38;5;241m=\u001b[39mopts\u001b[38;5;241m.\u001b[39mVisualMapOpts(min_\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m, max_\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1000\u001b[39m, range_text\u001b[38;5;241m=\u001b[39m[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m高校数量最少\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m高校数量最多\u001b[39m\u001b[38;5;124m\"\u001b[39m]),\n\u001b[0;32m     13\u001b[0m                      tooltip_opts\u001b[38;5;241m=\u001b[39mopts\u001b[38;5;241m.\u001b[39mTooltipOpts(formatter\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{b}\u001b[39;00m\u001b[38;5;124m: \u001b[39m\u001b[38;5;132;01m{c}\u001b[39;00m\u001b[38;5;124m所高校\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m     14\u001b[0m                      \n\u001b[0;32m     15\u001b[0m        )\n\u001b[0;32m     16\u001b[0m )\n\u001b[0;32m     17\u001b[0m maps\u001b[38;5;241m.\u001b[39mrender(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m./result/需求6：地图.html\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\pyecharts\\charts\\basic_charts\\map.py:53\u001b[0m, in \u001b[0;36mMapMixin.add\u001b[1;34m(self, series_name, data_pair, maptype, is_roam, center, aspect_scale, bounding_coords, min_scale_limit, max_scale_limit, name_property, selected_mode, zoom, name_map, symbol, map_value_calculation, is_map_symbol_show, z_level, z, pos_left, pos_top, pos_right, pos_bottom, geo_index, series_layout_by, dataset_index, layout_center, layout_size, label_opts, tooltip_opts, itemstyle_opts, emphasis_label_opts, emphasis_itemstyle_opts)\u001b[0m\n\u001b[0;32m     50\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mjs_dependencies\u001b[38;5;241m.\u001b[39madd(maptype)\n\u001b[0;32m     51\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_geo_json_name \u001b[38;5;241m=\u001b[39m maptype\n\u001b[1;32m---> 53\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(\u001b[43mdata_pair\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m, opts\u001b[38;5;241m.\u001b[39mMapItem):\n\u001b[0;32m     54\u001b[0m     data \u001b[38;5;241m=\u001b[39m data_pair\n\u001b[0;32m     55\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
      "\u001b[1;31mKeyError\u001b[0m: 0"
     ]
    }
   ],
   "source": [
    "maps = (\n",
    "    Map()\n",
    "    .add(series_name='高校数量',data_pair=china_regions,maptype='china',\n",
    "         is_map_symbol_show=False,  # 关闭点\n",
    "         is_roam=False,  # 取消滚轮缩放功能\n",
    "         center=[110,35],  # 位置\n",
    "         zoom=1.5,  # 控制地图大小\n",
    "         # itemstyle_opts=itemstyle_map,\n",
    "         \n",
    "        )\n",
    "    \n",
    "    .set_global_opts(visualmap_opts=opts.VisualMapOpts(min_=0, max_=1000, range_text=[\"高校数量最少\", \"高校数量最多\"]),\n",
    "                     tooltip_opts=opts.TooltipOpts(formatter=\"{b}: {c}所高校\")\n",
    "                     \n",
    "       )\n",
    ")\n",
    "maps.render('./result/需求6：地图.html')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c686700-9c1f-4b63-8781-055a9ccb8c28",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "32ddbfcb-9db3-465d-aa4b-dc800fb52257",
   "metadata": {},
   "source": [
    "## 任务3. 数据分析任务-相关性分析(工具:Seaborn)\n",
    "### 需求7: 利用中国大学综合排名2023.xlsx数据集,计算该数据集中下述字段\n",
    "排名,评分,办学层次,学科水平,办学资源,师资规模与结构,人才培养,科学研究,服务社会,高端人才,重大项目与成果,国际竞争力. 之间是否存在相关性.可使用seaborn完成\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e55a6cc-e974-48a6-babd-c3b59d2ba428",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c74468e-23a2-4981-bc19-bccc93ccdeff",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c067489d-7f34-4e12-adca-57401bfbd6bd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "2f8fd5af-8277-4e5c-8ce9-8f61e67afc4c",
   "metadata": {},
   "source": [
    "## 任务4: 数据可视化任务(Pyecharts完成)\n",
    "利用任务1最终合并的数据集all_school以及Pyecharts中TimeLine组件,完成时序图表的绘制完成可视化任务.具体需求如下:\n",
    "### 需求8: 最近10年全国各省211/985高校数量.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8836cbcf-ae9f-40d4-979e-68b9d81f711a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0427c34a-5f19-4e83-90a1-c2c6655abbb9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "9ea70abf-beda-4853-95dd-b6987d5db829",
   "metadata": {},
   "source": [
    "### 需求9: 完成最近10年中国大学综合排名TOP20高校动态排序条形图\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec9d3d42-571d-4055-b3f4-1e5036a1d4a3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8be7b98-f371-40d2-9e0a-41d8f42a6458",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "2805dbdb-e3e4-48d7-b5d1-c0c9652e1b42",
   "metadata": {},
   "source": [
    "### 需求10: 完成最近10年中国大学综合排名TOP20高校动态排序饼图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c28b65c5-14ff-4fc0-8f2d-83c8ccddd183",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fcf8a00e-1bd9-479b-9d83-b999722e3eef",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
